package cn.cvs.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.logging.Logger;

@Controller
@RequestMapping(value = "/hello")
public class HelloController {

    Logger logger = Logger.getLogger(HelloController.class.getName());

    @RequestMapping("/hello2")
    public String hello2(Model model, @RequestParam String realName) throws Exception {
        System.out.println("你好" + realName + "欢迎来到Spring MVC课堂。");
        model.addAttribute("realName", realName);
        model.addAttribute(realName);
        return "hello";
    }

    @RequestMapping("/hello3")
    public String hello3(Map<String, Object> map, @RequestParam String realName) throws Exception {
        System.out.println("你好" + realName + "欢迎来到Spring MVC课堂。");
        map.put("realName", realName);
        return null;
    }

    @PostMapping("/show")
    public String getAccount(@RequestParam("account") String account , HttpServletRequest request){
        System.out.println("account = " + account);
        request.setAttribute("account",account);
        return "show";
    }

    @GetMapping(value = "/account")
    public String account(Map<String, Object> map, HttpServletRequest request,String account) {
        map.put("account", account);
        return "hello";
    }

//    @RequestMapping(value = "/hello")
//    public String hello() throws Exception {
//        logger.info("我的第一个SpringMVC程序，运行成功拉！");
//        return "hello";
//    }
//
//                                                                                                          k0lo9,
//    @RequestMapping(value = "/hello2")
//    public String hello2() throws Exception {
//        logger.info("hello控制器下的另一个接口！");
//        return "hello";
//    }

//    @RequestMapping("/hello")
//    public String hello(@RequestParam(required = false) String realName) throws Exception {
//        System.out.println("你好"+realName+"欢迎来到Spring Mvc科泰");
//        return "hello";
//    }
//
//    @RequestMapping("/hello2")
//    public String hello2(@RequestParam(required = false,value = "userName") String realName) throws Exception {
//        System.out.println("你好"+realName+"欢迎来到Spring Mvc科泰");
//        return "hello";
//    }
//    @RequestMapping("/hello")
//    public ModelAndView hello(@RequestParam String realName) throws Exception{
//        System.out.println("你好" + realName + "欢迎来到Spring MVC课堂。");
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("realName", realName);
//        modelAndView.setViewName("hello");
//        return modelAndView;
//    }




//    @Override
//    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
//        System.out.println("Spring MVC架构搭建成功。");
//        return new ModelAndView("hello");
//    }
}
